unit CustomThreadBase;

interface

uses
  Classes, Windows;

Type
  TCustomThreadBase = class (TThread)
  private
    function GetStop: Boolean;
  public
      WaitForTerminateEvent : THandle;
      constructor Create(CreateSuspended: Boolean); virtual;
      destructor Destroy; override;
      Procedure Stop;
      Property Stopped: Boolean read GetStop;
  published
  end;

implementation

{ TThreadBase }

constructor TCustomThreadBase.Create(CreateSuspended: Boolean);
begin
  FreeOnTerminate := false;

  WaitForTerminateEvent := CreateEvent(nil, false, false, '');

  inherited Create(CreateSuspended);
end;

destructor TCustomThreadBase.Destroy;
begin
  CloseHandle(WaitForTerminateEvent);
  inherited;
end;

function TCustomThreadBase.GetStop: Boolean;
begin
  Result := self.Terminated;
end;

procedure TCustomThreadBase.Stop;
begin
  Self.Terminate;
end;

end.
